package pong;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class PongMessages 
{
	public static final int MSG_BALL = 221432;

	public PongMessages(){};
	
	public static void sendBall(DataOutputStream os, Ball ball)
	{
		try {
			System.out.println("Sending ball...");
			os.writeInt(MSG_BALL);
			os.writeDouble(ball.track_x[0]);
			os.writeDouble(ball.track_y[0]);
			os.writeInt(ball.speed);
			os.writeDouble(ball.angle);
			os.flush();
		
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static Ball getBall(DataInputStream is)
	{
		Ball new_ball = new Ball();
		try {
			System.out.println("getting ball...");
			is.readInt();
			new_ball.track_x[0] = is.readDouble();
			new_ball.track_y[0] = is.readDouble();
			new_ball.speed = is.readInt();
			new_ball.angle = is.readDouble();
						
		
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new_ball;
		
	}

}
